/**
 * Project: d20Engine
 * Created: Aug 9, 2006 by bebopJMM
 *------------------------------------------------------------------------------
 * $Id$
 */
package org.rollinitiative.d20.dice;

import java.util.Random;

/**
 * Singleton for generating dice rolling values.
 * 
 * @author bebopJMM
 * 
 */
public class Dice
{

   private Random random_;

   static Dice INSTANCE_ = null;


   private Dice()
   {
      this.random_ = new Random();
   }


   /**
    * @return
    */
   public static Dice getInstance()
   {
      if (INSTANCE_ == null) {
         INSTANCE_ = new Dice();
      }
      return INSTANCE_;
   }


   /**
    * 
    * @param numDice
    * @param sides
    * @param modifier
    * @return
    */
   public int roll(int numDice, int sides, int modifier)
   {
      int value = 0;
      for (int i = 0; i < numDice; i++) {
         value += 1 + (int) (random_.nextInt(sides));
      }
      return value + modifier;
   }

}
